import 'package:flutter/material.dart';

class SleepTimeComponent extends StatelessWidget {
  const SleepTimeComponent({super.key});

  @override
  Widget build(BuildContext context) {
    return const Row(
      mainAxisAlignment: MainAxisAlignment.spaceAround,
      children: [
        Item(type: 1),
        Item(type: 2),
        Item(type: 3),
      ],
    );
  }
}

class Item extends StatelessWidget {
  final type;

  const Item({super.key, this.type});

  @override
  Widget build(BuildContext context) {
    Color mColor = getDotColor(type);
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Row(
          children: [
            // 圆点
            Container(
              width: 6, // 圆点直径
              height: 6,
              decoration: BoxDecoration(
                shape: BoxShape.circle,
                color: mColor, // 圆点颜色
              ),
            ),
            const SizedBox(width: 2),
            //深睡、浅睡、醒
            Text(getText(type), style: const TextStyle(fontSize: 13, color: Color(0xFFA1A1AD))),
            const SizedBox(width: 2),
            const Text("16.1h", style: TextStyle(fontSize: 13, color: Colors.black)),
          ],
        ),
        Container(
          padding: const EdgeInsets.symmetric(horizontal: 2),
          margin: const EdgeInsets.only(left: 6),
          decoration: BoxDecoration(
            border: Border.all(color: const Color(0xFF61CB88), width: 1),
            //圆角半径
            borderRadius: const BorderRadius.all(Radius.circular(50.0)),
            //背景色
            // color: const Color(0xFFFFFBFF),
          ),
          child: const Text(
            "正常",
            style: TextStyle(fontSize: 10, color: Color(0xFF61CB88)),
          ),
        ),
      ],
    );
  }

  String getText(int type) {
    String text = "";
    if (type == 1) {
      text = "深睡";
    }
    if (type == 2) {
      text = "浅睡";
    }
    if (type == 3) {
      text = "醒";
    }
    return text;
  }

  Color getDotColor(int type) {
    Color color = Colors.transparent;
    if (type == 1) {
      color = const Color(0xFF2229B6);
    }
    if (type == 2) {
      color = const Color(0xFF2F82FA);
    }
    if (type == 3) {
      color = const Color(0xFF46BDFD);
    }
    return color;
  }
}
